*************************************************************************
* Bad governance: Privatization and corruption in the developing world
* 
* Contact: bernhard.reinsberg@glasgow.ac.uk
* July 15, 2019
*************************************************************************


* Preliminaries and descriptives
* ***********************************************************************

* Load data

  use "R&G_replication.dta", clear
    
  drop if incid==1

  g lngdppc=ln(gdppc_WDI)
  g lnpop=ln(unna_pop)
  g lnoilpc=ln(1+ross_oil_prod_QOG/unna_pop)
  g oilpc=ross_oil_prod_QOG/unna_pop
  g HRV_index=transparencyindex
  g ssa=(regid==7)
  g lic=(incid==2)

  sort cid year 
  xtset cid year  
  
  g IMFcum=.
  g Loancum=.
  forvalues i=1980/2014{
    g imf=IMFnn
	replace imf=. if year>`i' | year<=`i'-5
	egen IMF=sum(imf), by(cid)
	replace IMFcum=IMF if year==`i'
	drop imf IMF 
	
	g ploan=loan
	replace ploan=. if year>`i' | year<=`i'-5
	egen PLOAN=sum(ploan), by(cid)
	replace Loancum=ln(1+PLOAN) if year==`i'
	drop ploan PLOAN 
  }
  lab var IMFcum "Past programs"
  lab var Loancum "Prior use of IMF credit, logarithmized"
  
  global BMAmax  lngdppc p_durable_QOG p_polity2_QOG  pop_urb_tot_WDI min_gdp_WDI lnoilpc
  global LBMAmax  L.lngdppc L.p_durable_QOG L.p_polity2_QOG  L.pop_urb_tot_WDI L.min_gdp_WDI L.lnoilpc

  global BMAmin  lngdppc pwt_hci_QOG p_durable_QOG p_polity2_QOG pop_urb_tot_WDI gxp_gdp_WDI min_gdp_WDI lnoilpc 
  global LBMAmin  L.lngdppc L.pwt_hci_QOG L.p_durable_QOG L.p_polity2_QOG L.pop_urb_tot_WDI L.gxp_gdp_WDI L.min_gdp_WDI L.lnoilpc

  foreach ctrl in gdppc_WDI p_durable p_polity2 pop_urb min_gdp oilpc{
    g d`ctrl'=d.`ctrl'
	}
  g lndgdppc=ln(1+dgdppc_WDI)
  replace lndgdppc=-ln(1-dgdppc_WDI) if dgdppc_WDI<0
  g lndoilpc=ln(doilpc+1)
  replace lndoilpc=-ln(1-doilpc) if doilpc<0

  global DX lndgdppc dp_durable dp_polity2 dpop_urb dmin_gdp lndoilpc 
  global LDX l.lndgdppc l.dp_durable l.dp_polity2 l.dpop_urb l.dmin_gdp l.lndoilpc 

  qui xi:reg icrgPC i.cid i.year i.regid
  set matsize 2000
  cmp setup 
  
  
* Motivating example   

** Figure 1 **
  twoway line (BA2PRI icrgPC vdem_pubcor year) if iso3=="ALB" & year>=1990 & year<=2005

  
* Descriptives 
  
** Table 1 **  
  estpost summarize icrgPC ti_cpi vdem_corr HRV IMFnn BA2PRI BA2RTP BA2LAB BA2SOE BA2EXT  $BMAmax 
  esttab, cells("count mean sd min max") noobs replace label  
    
  
  
* Multivariate analysis
***********************************************************************  

* Table 2: Privatization conditions and corruption control 
  
  mat CIVDiag=J(5,5,0)

forvalues l=1/5{
  
  local k=`l'+1
  
  global X L`l'.lngdppc L`l'.p_durable_QOG L`l'.p_polity2_QOG  L`l'.pop_urb_tot_WDI L`l'.min_gdp_WDI L`l'.lnoilpc
  global Z L`k'.IMFcum L`k'.s_unga3g7 L`k'.nUnder L`k'.lngdppc L`k'.p_polity2_QOG L`k'.reserves L`k'.gdp_growth_WDI L`k'.debtser_gni L`k'.dpi_exelec _Iregid* _Iyear*
      
  di "BA2PRI `l'"
  qui egen var4=mean(BA2PRI), by(cid)
  qui gen int4=var4*L`l'.nUnder
 
  qui cmp (icrgPC =L`l'.BA2PRI L`l'.IMFnn $X _Icid* _Iyear*) (L`l'.BA2PRI=int4 $X _Icid* _Iyear*) (L`l'.IMFnn=$Z), indicators($cmp_cont $cmp_cont $cmp_probit) ro cl(cid) iterate(50)
  est store a`l'
  
  qui test [L`l'BA2PRI]int4
  mat CIVDiag[5,`l']=r(chi2)
  qui xtreg icrgPC int4 L`l'.IMFnn $X _Iyear*, fe 
  mat CIVDiag[2,`l']=e(r2_w)
  mat CIVDiag[1,`l']=e(N)
  
  qui xtreg L`l'.BA2PRI int4 $X _Iyear*, fe 
  mat CIVDiag[4,`l']=e(r2_w)
  
  qui probit L`l'.IMFnn $Z 
  mat CIVDiag[3,`l']=e(r2_p)
	 
  drop var* int*
  }
  
** Table 2 **
  estout a*, starlevels(* .1 ** .05 *** .01) cells(b(star fmt(3)) se(par fmt(3))) drop(_cons *year* _I*) keep(icrgPC:) 
  mat li CIVDiag 
  

* Table 3: Implementation-corrected conditionality counts and corruption control.

  mat CIV=J(4,5,0)
  mat CIVDiag=J(3,5,0)

forvalues l=1/5{
  
  local k=`l'+1
  global X L`l'.lngdppc L`l'.p_durable_QOG L`l'.p_polity2_QOG  L`l'.pop_urb_tot_WDI L`l'.min_gdp_WDI L`l'.lnoilpc
  global Z L`k'.IMFcum L`k'.s_unga3g7 L`k'.nUnder L`k'.lngdppc L`k'.p_polity2_QOG L`k'.reserves L`k'.gdp_growth_WDI L`k'.debtser_gni L`k'.dpi_exelec _Iregid* _Iyear*
 
  di "cBAPRI `l'"
  qui egen var4=mean(cBAPRI), by(cid)
  qui gen int4=var4*L`l'.nUnder
 
  qui cmp (icrgPC =L`l'.cBAPRI L`l'.IMFnn $X _Icid* _Iyear*) (L`l'.cBAPRI=int4 $X _Icid* _Iyear*) (L`l'.IMFnn=$Z), indicators($cmp_cont $cmp_cont $cmp_probit) ro cl(cid) iterate(50)
   mat B=e(b)
   mat S=e(V)
   mat CIV[1,`l']=B[1,1]
   mat CIV[2,`l']=sqrt(S[1,1])
   mat CIV[3,`l']=B[1,2]
   mat CIV[4,`l']=sqrt(S[2,2])
  
  qui test [L`l'cBAPRI]int4
  mat CIVDiag[3,`l']=r(chi2)
  qui xtreg icrgPC  int4 L`l'.IMFnn $X _Iyear* if e(sample), fe 
  mat CIVDiag[1,`l']=e(r2_w)
  mat CIVDiag[2,`l']=e(N)
	 
  drop var* int*
  } 

** Table 3 **
  mat li CIV
  mat li CIVDiag

  
  
* Table 4: Privatization conditions and other policy conditions.

  mat CIV=J(6,4,0)
  mat CIVDiag=J(4,4,0)
  
  local l=2
  local k=`l'+1
  di "Level lag=`l'"
  local m=1

  foreach x in BA2RTP BA2LAB BA2SOE BA2EXT {
  
  global X L`l'.lngdppc L`l'.p_durable_QOG L`l'.p_polity2_QOG  L`l'.pop_urb_tot_WDI L`l'.min_gdp_WDI L`l'.lnoilpc
  global Z L`k'.IMFcum L`k'.s_unga3g7 L`k'.nUnder L`k'.lngdppc L`k'.p_polity2_QOG L`k'.reserves L`k'.gdp_growth_WDI L`k'.debtser_gni L`k'.dpi_exelec _Iregid* _Iyear*
       
  qui egen PRIm=mean(BA2PRI), by(cid)
  qui gen PRIIV=PRIm*L`l'.nUnder
  qui egen `x'm=mean(`x'), by(cid)
  qui gen `x'IV=`x'm*L`l'.nUnder
  di "`x'"
  
  qui cmp (icrgPC =L`l'.BA2PRI L`l'.`x' L`l'.IMFnn $X _Icid* _Iyear*) (L`l'.`x'=`x'IV $X _Icid* _Iyear*) (L`l'.BA2PRI=PRIIV $X _Icid* _Iyear*) (L`l'.IMFnn=$Z), indicators($cmp_cont $cmp_cont $cmp_cont $cmp_probit) ro cl(cid) iterate(200)
   mat B=e(b)
   mat S=e(V)
   mat CIV[1,`m']=B[1,1]
   mat CIV[2,`m']=sqrt(S[1,1])
   mat CIV[3,`m']=B[1,2]
   mat CIV[4,`m']=sqrt(S[2,2])
   mat CIV[5,`m']=B[1,3]
   mat CIV[6,`m']=sqrt(S[3,3])
 
  qui test [L`l'BA2PRI]PRIIV
  mat CIVDiag[3,`m']=r(chi2)
  qui test [L`l'`x']`x'IV
  mat CIVDiag[4,`m']=r(chi2)
  
  qui xtreg icrgPC PRIIV `x'IV L`l'.IMFnn $X _Iyear* if e(sample), fe 
  mat CIVDiag[1,`m']=e(r2_w)
  mat CIVDiag[2,`m']=e(N)
	 
  drop PRI* `x'IV `x'm
  local m=`m'+1
  }

** Table 4 **  
  mat li CIV
  mat li CIVDiag

  

  
* Supplemental appendix
******************************************************************

* Table A1: Different measures of corruption.

  local l=1
  local k=2
  qui reg icrgPC L`l'.lngdppc L`l'.p_durable_QOG L`l'.p_polity2_QOG  L`l'.pop_urb_tot_WDI L`l'.min_gdp_WDI L`l'.lnoilpc L`k'.IMFcum L`k'.s_unga3g7 L`k'.nUnder L`k'.lngdppc L`k'.p_polity2_QOG L`k'.reserves L`k'.gdp_growth_WDI L`k'.debtser_gni L`k'.dpi_exelec _Iregid* _Iyear*
  g sICRG=(e(sample))
  
  mat CIVDiag=J(3,9,0)
  mat C1=J(4,9,0)
  local t=0
  
  foreach y in ti_cpi vdem_corr{
  
  forvalues l=1/3{
 
  local k=`l'+1
  di "Level lag=`l'"
  
  qui egen var4=mean(BA2PRI), by(cid)
  qui gen int4=var4*L`l'.nUnder
  
  global X L`l'.lngdppc L`l'.p_durable_QOG L`l'.p_polity2_QOG  L`l'.pop_urb_tot_WDI L`l'.min_gdp_WDI L`l'.lnoilpc
  global Z L`k'.IMFcum L`k'.s_unga3g7 L`k'.nUnder L`k'.lngdppc L`k'.p_polity2_QOG L`k'.reserves L`k'.gdp_growth_WDI L`k'.debtser_gni L`k'.dpi_exelec _Iregid* _Iyear*
   
  qui cmp (`y'=L`l'.BA2PRI L`l'.IMFnn $X _Icid* _Iyear*) (L`l'.BA2PRI=int4 $X _Icid* _Iyear*) (L`l'.IMFnn=$Z), indicators($cmp_cont $cmp_cont $cmp_probit) ro cl(cid) iterate(80)
   mat B=e(b)
   mat B1=B[1,1]
   mat B2=B[1,2]
   mat S=e(V)
   mat S1=sqrt(S[1,1])
   mat S2=sqrt(S[2,2])
   mat C1[1,3*`t'+`l']=B1
   mat C1[2,3*`t'+`l']=S1
   mat C1[3,3*`t'+`l']=B2
   mat C1[4,3*`t'+`l']=S2
  
  qui test [L`l'BA2PRI]int4
  mat CIVDiag[3,3*`t'+`l']=r(chi2)
  qui xtreg `y' int4 L`l'.IMFnn $X _Iyear* if e(sample), fe 
  mat CIVDiag[2,3*`t'+`l']=e(r2_w)
  mat CIVDiag[1,3*`t'+`l']=e(N)
  drop var4 int4
  }
  local t=`t'+1
  }
  
  ** HRV 
  forvalues l=1/3{
 
  local k=`l'+1
  di "Level lag=`l'"
  
  qui egen var4=mean(BA2PRI), by(cid)
  qui gen int4=var4*L`l'.nUnder
  
  global X L`l'.lngdppc L`l'.p_durable_QOG L`l'.p_polity2_QOG  L`l'.pop_urb_tot_WDI L`l'.min_gdp_WDI L`l'.lnoilpc
  global Z L`k'.IMFcum L`k'.s_unga3g7 L`k'.nUnder L`k'.lngdppc L`k'.p_polity2_QOG L`k'.reserves L`k'.gdp_growth_WDI L`k'.debtser_gni L`k'.dpi_exelec _Iregid* _Iyear*
  qui xtreg icrgPC $X $Z _Iyear*, fe
 
  qui cmp (HRV_index=L`l'.BA2PRI L`l'.IMFnn $X _Icid* _Iyear*) (L`l'.BA2PRI=int4 $X _Icid* _Iyear*) (L`l'.IMFnn=$Z) if e(sample), indicators($cmp_cont $cmp_cont $cmp_probit) ro cl(cid) iterate(50)
   mat B=e(b)
   mat B1=B[1,1]
   mat B2=B[1,2]
   mat S=e(V)
   mat S1=sqrt(S[1,1])
   mat S2=sqrt(S[2,2])
   mat C1[1,3*`t'+`l']=B1
   mat C1[2,3*`t'+`l']=S1
   mat C1[3,3*`t'+`l']=B2
   mat C1[4,3*`t'+`l']=S2
  
  qui test [L`l'BA2PRI]int4
  mat CIVDiag[3,3*`t'+`l']=r(chi2)
  qui xtreg HRV_index int4 L`l'.IMFnn $X _Iyear* if e(sample), fe 
  mat CIVDiag[2,3*`t'+`l']=e(r2_w)
  mat CIVDiag[1,3*`t'+`l']=e(N)
  drop var4 int4
  }
  
** Table A1 **
  mat li C1
  mat li CIVDiag


* Table A2: Alternative operationalization of compound instruments.  

  mat CIV=J(10,5,0)
  mat CIVDiag=J(15,5,0)

forvalues l=1/5{
  
  local k=`l'+1
  di "Level lag=`l'"
  
  global X L`l'.lngdppc L`l'.p_durable_QOG L`l'.p_polity2_QOG  L`l'.pop_urb_tot_WDI L`l'.min_gdp_WDI L`l'.lnoilpc  
  global Z L`k'.IMFcum L`k'.s_unga3g7 L`k'.nUnder L`k'.lngdppc L`k'.p_polity2_QOG L`k'.reserves L`k'.gdp_growth_WDI L`k'.debtser_gni L`k'.dpi_exelec _Iregid* _Iyear*
 
  local t=0
  foreach var in BA2PRI BA2RTP BA2LAB BA2SOE BA2EXT {
      
  local t=`t'+1
  di "`var'"
  qui egen var4=mean(`var'), by(cid)
  qui egen vart=mean(`var'), by(year)
  qui gen int4=var4*L`l'.vart
 
  qui cmp (icrgPC =L`l'.`var' L`l'.IMFnn $X _Icid* _Iyear*) (L`l'.`var'=int4 $X _Icid* _Iyear*) (L`l'.IMFnn=$Z), indicators($cmp_cont $cmp_cont $cmp_probit) ro cl(cid) iterate(150)
   mat B=e(b)
   mat B1=B[1,1]
   mat B2=B[1,2]
   mat S=e(V)
   mat S1=sqrt(S[1,1])
   mat S2=sqrt(S[2,2])
   mat CIV[2*`t'-1,`l']=B1
   mat CIV[2*`t',`l']=S1

  qui test [L`l'`var']int4
  mat CIVDiag[3*`t'-2,`l']=r(chi2)
  qui xtreg icrgPC int4 L`l'.IMFnn _Iyear*, fe 
  mat CIVDiag[3*`t',`l']=e(r2_w)
  mat CIVDiag[3*`t'-1,`l']=e(N)
	 
  drop var* int4
  }
  }
  
** Table A2 **
  mat li CIV
  mat li CIVDiag


* Table A3: Conditionality effects under different control group.

  mat CIV=J(10,5,0)
  mat CIVDiag=J(15,5,0)

forvalues l=1/5{
  
  local k=`l'+1
  di "Level lag=`l'"
  global X L`l'.lngdppc L`l'.p_durable_QOG L`l'.p_polity2_QOG  L`l'.pop_urb_tot_WDI L`l'.min_gdp_WDI L`l'.lnoilpc
 
  local t=0
  
  foreach var in BA2PRI BA2RTP BA2LAB BA2SOE BA2EXT {
      
  local t=`t'+1
  di "`var' `l'"
  qui egen var4=mean(`var'), by(cid)
  qui gen int4=var4*L`l'.nUnder
 
  qui cmp (icrgPC =L`l'.`var' L`l'.IMFnn $X _Icid* _Iyear*) (L`l'.`var'=int4 $X _Icid* _Iyear*) if L`l'.IMFnn==1, indicators($cmp_cont $cmp_cont) ro cl(cid) iterate(150)
   mat B=e(b)
   mat B1=B[1,1]
   mat B2=B[1,2]
   mat S=e(V)
   mat S1=sqrt(S[1,1])
   mat S2=sqrt(S[2,2])
   mat CIV[2*`t'-1,`l']=B1
   mat CIV[2*`t',`l']=S1
 
  qui test [L`l'`var']int4
  mat CIVDiag[3*`t'-2,`l']=r(chi2)
  qui xtreg icrgPC int4 L`l'.IMFnn _Iyear* if e(sample), fe 
  mat CIVDiag[3*`t',`l']=e(r2_w)
  mat CIVDiag[3*`t'-1,`l']=e(N)
	 
  drop var* int*
  }
  }
  
** Table A3 **  
  mat li CIV
  mat li CIVDiag
  

* Table A4: Dynamic effects of IMF conditions on corruption control.

  global DX lndgdppc dp_durable dp_polity2 dpop_urb dmin_gdp lndoilpc 
  global X L.lngdppc L.p_durable_QOG L.p_polity2_QOG  L.pop_urb_tot_WDI L.min_gdp_WDI L.lnoilpc
  global Z L2.IMFcum L2.s_unga3g7 L2.nUnder L2.lngdppc L2.p_polity2_QOG L2.reserves L2.gdp_growth_WDI L2.debtser_gni L2.dpi_exelec _Iregid* _Iyear*

  qui xi:reg icrgPC i.cid i.year i.regid
  set matsize 800
  cmp setup 
  
  mat ESST=J(10,5,0)
  mat ESSTD=J(3,5,0)
	
  local t=0
  
  foreach var in BA2PRI BA2RTP BA2LAB BA2SOE BA2EXT {
      
  local t=`t'+1
  di "`var'"
  qui egen var4=mean(`var'), by(cid)
  qui gen int4=var4*L.nUnder
 
  qui cmp (d.icrgPC =d.`var' l.`var' d.IMFnn l.IMFnn l.icrgPC $X $DX _Icid* l.year) (L.`var'=int4 $X _Icid* l.year) (L.IMFnn=$Z), indicators($cmp_cont $cmp_cont $cmp_probit) ro cl(cid) iterate(50)
   mat B=e(b)
   mat S=e(V)
   mat ESST[1,`t']=B[1,1]
   mat ESST[2,`t']=sqrt(S[1,1])
   mat ESST[3,`t']=B[1,2]
   mat ESST[4,`t']=sqrt(S[2,2])
   mat ESST[5,`t']=B[1,3]
   mat ESST[6,`t']=sqrt(S[3,3])
   mat ESST[7,`t']=B[1,4]
   mat ESST[8,`t']=sqrt(S[4,4])
   mat ESST[9,`t']=B[1,5]
   mat ESST[10,`t']=sqrt(S[5,5])

  qui test [L`var']int4
  mat ESSTD[1,`t']=r(chi2)
  qui xtreg d.icrgPC l.icrgPC d.`var' int4 d.IMFnn l.IMFnn $X $DX l.year, fe 
  mat ESSTD[2,`t']=e(r2_w)
  mat ESSTD[3,`t']=e(N)
  drop var* int*
  }

** Table A4 **
  mat li ESST
  mat li ESSTD
  
  
* Table A5: Taking government spending into account.

  mat BDiag=J(3,6,0)
  
  local t=1
  g dmil=d.wdi_expmil 
  g dgxp=d.gxp_gdp

  local l=3
  local k=`l'+1
  global X L`l'.lngdppc L`l'.p_durable_QOG L`l'.p_polity2_QOG  L`l'.pop_urb_tot_WDI L`l'.min_gdp_WDI L`l'.lnoilpc
  global Z L`k'.IMFcum L`k'.s_unga3g7 L`k'.nUnder L`k'.lngdppc L`k'.p_polity2_QOG L`k'.reserves L`k'.gdp_growth_WDI L`k'.debtser_gni L`k'.dpi_exelec _Iregid* _Iyear*
 
  qui egen var4=mean(BA2PRI), by(cid)
  qui gen int4=var4*L`l'.nUnder
  
  foreach z in gxp_gdp dgxp wdi_expmil dmil {
  
  qui cmp (icrgPC =L`l'.BA2PRI L`l'.IMFnn L`l'.`z' $X _Icid* _Iyear*) (L`l'.BA2PRI=int4 $X _Icid* _Iyear*) (L`l'.IMFnn=$Z), indicators($cmp_cont $cmp_cont $cmp_probit) ro cl(cid) iterate(50)
   est store z`t'
   qui test [L`l'BA2PRI]int4
   mat BDiag[3,`t']=r(chi2)
   qui xtreg icrgPC int4 L`l'.IMFnn L`l'.`z' $X _Iyear* if e(sample), fe 
   mat BDiag[2,`t']=e(r2_w)
   mat BDiag[1,`t']=e(N)
  
  local t=`t'+1
  }
  
  qui g priXZ1=L`l'.BA2PRI*L`l'.dgxp 
  qui cmp (icrgPC =L`l'.BA2PRI priXZ1 L`l'.IMFnn L`l'.dgxp $X _Icid* _Iyear*) (L`l'.BA2PRI=int4 $X _Icid* _Iyear*) (L`l'.IMFnn=$Z), indicators($cmp_cont $cmp_cont $cmp_probit) ro cl(cid) iterate(50)
   est store zx1
   test [L`l'BA2PRI]int4
  
  qui g priXZ2=L`l'.BA2PRI*L`l'.dmil
   qui cmp (icrgPC =L`l'.BA2PRI priXZ2 L`l'.IMFnn L`l'.dmil $X _Icid* _Iyear*) (L`l'.BA2PRI=int4 $X _Icid* _Iyear*) (L`l'.IMFnn=$Z), indicators($cmp_cont $cmp_cont $cmp_probit) ro cl(cid) iterate(50)
   est store zx2
   test [L`l'BA2PRI]int4
  
  drop var4 int4 priXZ*
  mat li BDiag

  estout z1 z2 zx1 z3 z4 zx2, starlevels(* .1 ** .05 *** .01) cells(b(star fmt(3)) se(par fmt(3))) stats(r2_w N F, fmt(%7.2f %7.0f %7.2f)) drop(_cons *year* _I*) keep(icrgPC:) 


* Table A6: Standardized coefficients for estimation using ‘control of corruption’.

  ** Standardize data 
  foreach x in icrgPC vdem_corr ti_cpi HRV_index  BA2PRI cBAPRI BA2EXT lngdppc p_durable p_polity2 pop_urb min_gdp lnoilpc IMFcum s_unga3g7 nUnder reserves gdp_growth debtser_gni dpi_exelec  lndgdppc dp_durable dp_polity2 dpop_urb dmin_gdp lndoilpc {
  qui egen std_`x'=std(`x')
  }
  
  su std_*
  
  mat SDiag=J(7,5,0)

  ** Static AR(3)
  local l=3
  local k=4
  
  global X L`l'.std_lngdppc L`l'.std_p_durable L`l'.std_p_polity2  L`l'.std_pop_urb L`l'.std_min_gdp L`l'.std_lnoilpc
  global Z L`k'.std_IMFcum L`k'.std_s_unga3g7 L`k'.std_nUnder L`k'.std_lngdppc L`k'.std_p_polity2 L`k'.std_reserves L`k'.std_gdp_growth L`k'.std_debtser_gni L`k'.std_dpi_exelec _Iregid* _Iyear*
      
  di "`var' `l'"
  qui egen var4=mean(std_BA2PRI), by(cid)
  qui gen int4=var4*L`l'.std_nUnder
 
  qui cmp (std_icrgPC =L`l'.std_BA2PRI L`l'.IMFnn $X _Icid* _Iyear*) (L`l'.std_BA2PRI=int4 $X _Icid* _Iyear*) (L`l'.IMFnn=$Z), indicators($cmp_cont $cmp_cont $cmp_probit) ro cl(cid) iterate(50)
  est store std1
    qui test [L`l'std_BA2PRI]int4
    mat SDiag[7,1]=r(chi2)
    qui xtreg std_icrgPC int4 L`l'.IMFnn $X _Iyear*, fe 
    mat SDiag[2,1]=e(r2_w)
    mat SDiag[1,1]=e(N)
  
    qui xtreg L`l'.std_BA2PRI int4 $X _Iyear*, fe 
    mat SDiag[5,1]=e(N)
    mat SDiag[6,1]=e(r2_w)
  
    qui probit L`l'.IMFnn $Z 
	mat SDiag[3,1]=e(N)
	mat SDiag[4,1]=e(r2_p)
	 
  ** Static AR(3) - implementation
  qui egen var5=mean(std_cBAPRI), by(cid)
  qui g int5=var5*L`l'.std_nUnder 
  
  qui cmp (std_icrgPC =L`l'.std_cBAPRI L`l'.IMFnn $X _Icid* _Iyear*) (L`l'.std_cBAPRI=int5 $X _Icid* _Iyear*) (L`l'.IMFnn=$Z), indicators($cmp_cont $cmp_cont $cmp_probit) ro cl(cid) iterate(50)
  est store std2
    qui test [L`l'std_cBAPRI]int5
    mat SDiag[7,2]=r(chi2)
    qui xtreg std_icrgPC int5 L`l'.IMFnn $X _Iyear*, fe 
    mat SDiag[2,2]=e(r2_w)
    mat SDiag[1,2]=e(N)
  
    qui xtreg L`l'.std_cBAPRI int5 $X _Iyear*, fe 
    mat SDiag[5,2]=e(N)
    mat SDiag[6,2]=e(r2_w)
  
    qui probit L`l'.IMFnn $Z 
	mat SDiag[3,2]=e(N)
	mat SDiag[4,2]=e(r2_p)
	
  ** Static AR(3) -- different IV
  qui egen vart=mean(std_BA2PRI), by(year)
  qui gen intt=var4*L`l'.vart
 
  qui cmp (std_icrgPC =L`l'.std_BA2PRI L`l'.IMFnn $X _Icid* _Iyear*) (L`l'.std_BA2PRI=intt $X _Icid* _Iyear*) (L`l'.IMFnn=$Z), indicators($cmp_cont $cmp_cont $cmp_probit) ro cl(cid) iterate(50)
  est store std4
    qui test [L`l'std_BA2PRI]intt
    mat SDiag[7,4]=r(chi2)
    qui xtreg std_icrgPC intt L`l'.IMFnn $X _Iyear*, fe 
    mat SDiag[2,4]=e(r2_w)
    mat SDiag[1,4]=e(N)
  
    qui xtreg L`l'.std_BA2PRI intt $X _Iyear*, fe 
    mat SDiag[5,4]=e(N)
    mat SDiag[6,4]=e(r2_w)
  
    qui probit L`l'.IMFnn $Z 
	mat SDiag[3,4]=e(N)
	mat SDiag[4,4]=e(r2_p)	
	
  ** Comparison at lag 3
  qui cmp (std_icrgPC =L`l'.std_BA2PRI $X _Icid* _Iyear*) (L`l'.std_BA2PRI=int4 $X _Icid* _Iyear*) if L`l'.IMFnn==1, indicators($cmp_cont $cmp_cont) ro cl(cid) iterate(50)
  est store std5
    qui test [L`l'std_BA2PRI]int4
    mat SDiag[7,5]=r(chi2)
    qui xtreg std_icrgPC int4 $X _Iyear*, fe 
    mat SDiag[2,5]=e(r2_w)
    mat SDiag[1,5]=e(N)
  
    qui xtreg L`l'.std_BA2PRI int4 $X _Iyear*, fe 
    mat SDiag[5,5]=e(N)
    mat SDiag[6,5]=e(r2_w)
	
  ** With EXT condition at lag 2
  local l=2
  local k=3
  
  drop int4 var4 
  qui egen var4=mean(std_BA2PRI), by(cid)
  qui gen int4=var4*L`l'.std_nUnder
  qui egen varext=mean(std_BA2EXT), by(cid)
  qui gen intext=varext*L`l'.std_BA2EXT
  
  qui cmp (std_icrgPC =L`l'.std_BA2PRI L`l'.std_BA2EXT L`l'.IMFnn $X _Icid* _Iyear*) (L`l'.std_BA2PRI=int4 $X _Icid* _Iyear*) (L`l'.std_BA2EXT=intext $X _Icid* _Iyear*) (L`l'.IMFnn=$Z), indicators($cmp_cont $cmp_cont $cmp_cont $cmp_probit) ro cl(cid) iterate(50)
  est store std3
    qui test [L`l'std_BA2PRI]int4
    mat SDiag[7,3]=r(chi2)
    qui xtreg std_icrgPC int4 L`l'.IMFnn $X _Iyear*, fe 
    mat SDiag[2,3]=e(r2_w)
    mat SDiag[1,3]=e(N)
  
    qui xtreg L`l'.std_BA2PRI int4 $X _Iyear*, fe 
    mat SDiag[5,3]=e(N)
    mat SDiag[6,3]=e(r2_w)
  
    qui probit L`l'.IMFnn $Z 
	mat SDiag[3,3]=e(N)
	mat SDiag[4,3]=e(r2_p)
	
** Table A6 **	
  estout std*, starlevels(* .1 ** .05 *** .01) cells(b(star fmt(3)) se(par fmt(3))) drop(_cons *year* _I*) keep(std_icrgPC:) order(*PRI*)
  mat li SDiag
   

* Table A7: Standardized coefficients for additional outcomes.

  mat SA1Diag=J(3,3,0)
  
  qui cmp (std_ti_cpi =L`l'.std_BA2PRI L`l'.IMFnn $X _Icid* _Iyear*) (L`l'.std_BA2PRI=int4 $X _Icid* _Iyear*) (L`l'.IMFnn=$Z), indicators($cmp_cont $cmp_cont $cmp_probit) ro cl(cid) iterate(50)
  est store stda1A
    qui test [L`l'std_BA2PRI]int4
    mat SA1Diag[3,1]=r(chi2)
    qui xtreg std_ti_cpi int4 L`l'.IMFnn $X _Iyear*, fe 
    mat SA1Diag[2,1]=e(r2_w)
    mat SA1Diag[1,1]=e(N)
  
  qui cmp (std_vdem_corr =L`l'.std_BA2PRI L`l'.IMFnn $X _Icid* _Iyear*) (L`l'.std_BA2PRI=int4 $X _Icid* _Iyear*) (L`l'.IMFnn=$Z), indicators($cmp_cont $cmp_cont $cmp_probit) ro cl(cid) iterate(50)
  est store stda1B
    qui test [L`l'std_BA2PRI]int4
    mat SA1Diag[3,2]=r(chi2)
    qui xtreg std_vdem_corr int4 L`l'.IMFnn $X _Iyear*, fe 
    mat SA1Diag[2,2]=e(r2_w)
    mat SA1Diag[1,2]=e(N)
  qui xtreg icrgPC $X $Z _Iyear*, fe	
  
  qui cmp (std_HRV_index =L`l'.std_BA2PRI L`l'.IMFnn $X _Icid* _Iyear*) (L`l'.std_BA2PRI=int4 $X _Icid* _Iyear*) (L`l'.IMFnn=$Z) if e(sample), indicators($cmp_cont $cmp_cont $cmp_probit) ro cl(cid) iterate(50)
  est store stda1C
    qui test [L`l'std_BA2PRI]int4
    mat SA1Diag[3,3]=r(chi2)
    qui xtreg std_HRV int4 L`l'.IMFnn $X _Iyear* if e(sample), fe 
    mat SA1Diag[2,3]=e(r2_w)
    mat SA1Diag[1,3]=e(N)
  
** Table A7 **  
  estout stda1*, starlevels(* .1 ** .05 *** .01) cells(b(star fmt(3)) se(par fmt(3))) stats(r2_w N F, fmt(%7.2f %7.0f %7.2f)) drop(_cons *year* _I*) keep() 
  mat li SA1Diag  

  
* Table B2: Correlation matrices 

  estpost summarize icrgPC ti_cpi vdem_corr HRV IMFnn BA2PRI BA2RTP BA2LAB BA2SOE BA2EXT  $BMAmax 
  esttab, cells("count mean sd min max") noobs replace label  
  
  corr icrgPC IMFnn BA2PRI BA2RTP BA2LAB BA2SOE BA2EXT  $BMAmax

* Additional variables

  corr icrgPC ti_cpi vdem_corr HRV 

  
***  
  